﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Media3D;
using Wen.Core;

namespace Wen.UI
{
	internal class LightIndicator
	{
		private readonly Viewport3D _viewport3D;
		private readonly Sphere _sphere;

		internal bool IsVisible {
			set {
				_sphere.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
			}
		}

		internal Point3D Position {
			set {
				if (_sphere.Visibility == Visibility.Visible)
					_sphere.Transform = new TranslateTransform3D(value.X, value.Y, value.Z);
			}
		}

		internal LightIndicator(Viewport3D viewport3D, bool isReducedSize, Point3D position) {
			_viewport3D = viewport3D;
			ProjectionCamera projectionCamera = (ProjectionCamera)viewport3D.Camera;
			double radius = (projectionCamera.Position.X + projectionCamera.Position.Y + projectionCamera.Position.Z) / 60.0;
			if (radius < 1)
				radius = 1;
			if (isReducedSize)
				radius /= 3.0;
			_sphere = new Sphere {
				Radius = radius,
				Visibility = Visibility.Collapsed
			};
			Position = position;
			_viewport3D.Children.Insert(_viewport3D.Children.Count, _sphere);
		}

		internal void Remove() {
			_viewport3D.Children.Remove(_sphere);
		}
	}
}
